<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@page import="com.liuya.safe.model.SafePrivilege" %>
<%@ page import="com.liuya.common.I18N" %>
<%
    I18N i18n = I18N.getInstance();
    SafePrivilege node = (SafePrivilege) request.getAttribute("node");
%>
<form id="modifyForm" action="update.do?oper=update" method="post">
    <input type="hidden" name="id" value="n<%=node.getId()%>"/>
    <input type="hidden" name="parentId" value="n<%=node.getPid()%>"/>
    <input type="hidden" name="isLeaf" value="<%=node.getIsLeaf()%>"/>
    <input type="hidden" name="orderNum" value="<%=node.getOrderNum()%>"/>
    <input type="hidden" name="status" value="<%=node.getStatus()%>"/>

    <label><%=i18n.say("Name") %>
    </label>
    <input name="name" type="text" size="50" value="<%=node.getName()%>"><br/>
    <label><%=i18n.say("Description") %>
    </label>
    <input name="description" type="text" size="50" value="<%=node.getDescription()%>"/><br/>
    <label><%=i18n.say("Display_in_menu") %>
    </label>
    <input name="display" type="radio" value="true" <%=node.getDisplay() ? "checked" : "" %>/> Yes
    <input name="display" type="radio" value="false" <%=node.getDisplay() ? "" : "checked" %>/> No<br/>
    <%if (node.getIsLeaf()) { %>
    <label><%=i18n.say("Constant_name") %>
    </label>
    <input name="constantName" type="text" size="50" value="<%=node.getConstantName()%>"/><br/>
    <label><%=i18n.say("Target") %>
    </label>
    <input name="target" type="text" size="50" value="<%=node.getTarget() %>"/><br/>
    <label><%=i18n.say("URL") %>
    </label>
    <input name="url" type="text" size="50" value="<%=node.getUrl() %>"/><br/>
    <% } %>
    <input type="submit" value="OK"/>
</form>
<script language="javascript">
    var modifyOptions = {
        beforeSubmit: beforeModify,
        success: afterModify,
        clearForm: true
    };

    // validate
    jQuery('#modifyForm').validate({
        rules: {
            name: {
                required: true,
                remote: {
                    url: "isNameValid.do?oper=isNameValid&id=n<%=node.getId()%>",
                    type: "GET",
                    dataType: "json",
                    data: {
                        name: function () {
                            return jQuery("#modifyForm :input[name=name]").val();
                        }
                    }
                }
            }
            <%if( node.getIsLeaf() ) {%>
            , constantName: {
                required: true
            }
            <%}%>
        }
    });

    // bind form using 'ajaxForm'
    jQuery('#modifyForm').ajaxForm(modifyOptions);
</script>